package com.qpkj.web.controller.oms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qpkj.common.annotation.Log;
import com.qpkj.common.core.controller.BaseController;
import com.qpkj.common.core.domain.AjaxResult;
import com.qpkj.common.enums.BusinessType;
import com.qpkj.oms.domain.OmsTaskStep;
import com.qpkj.oms.service.IOmsTaskStepService;
import com.qpkj.common.utils.poi.ExcelUtil;
import com.qpkj.common.core.page.TableDataInfo;

/**
 * 任务步骤Controller
 *
 * @author ruoyi
 * @date 2022-12-20
 */
@RestController
@RequestMapping("/oms/taskstep")
public class OmsTaskStepController extends BaseController {
    @Autowired
    private IOmsTaskStepService omsTaskStepService;

    /**
     * 查询任务步骤列表
     */
    @PreAuthorize("@ss.hasPermi('oms:taskstep:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsTaskStep omsTaskStep) {
        startPage();
        List<OmsTaskStep> list = omsTaskStepService.selectOmsTaskStepList(omsTaskStep);
        return getDataTable(list);
    }

    /**
     * 导出任务步骤列表
     */
    @PreAuthorize("@ss.hasPermi('oms:taskstep:export')")
    @Log(title = "任务步骤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsTaskStep omsTaskStep) {
        List<OmsTaskStep> list = omsTaskStepService.selectOmsTaskStepList(omsTaskStep);
        ExcelUtil<OmsTaskStep> util = new ExcelUtil<OmsTaskStep>(OmsTaskStep.class);
        util.exportExcel(response, list, "任务步骤数据");
    }

    /**
     * 获取任务步骤详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:taskstep:query')")
    @GetMapping(value = "/{stepId}")
    public AjaxResult getInfo(@PathVariable("stepId") Long stepId) {
        return success(omsTaskStepService.selectOmsTaskStepByStepId(stepId));
    }

    /**
     * 新增任务步骤
     */
    @PreAuthorize("@ss.hasPermi('oms:taskstep:add')")
    @Log(title = "任务步骤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsTaskStep omsTaskStep) {
        return toAjax(omsTaskStepService.insertOmsTaskStep(omsTaskStep));
    }

    /**
     * 修改任务步骤
     */
    @PreAuthorize("@ss.hasPermi('oms:taskstep:edit')")
    @Log(title = "任务步骤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsTaskStep omsTaskStep) {
        return toAjax(omsTaskStepService.updateOmsTaskStep(omsTaskStep));
    }

    /**
     * 删除任务步骤
     */
    @PreAuthorize("@ss.hasPermi('oms:taskstep:remove')")
    @Log(title = "任务步骤", businessType = BusinessType.DELETE)
    @DeleteMapping("/{stepIds}")
    public AjaxResult remove(@PathVariable Long[] stepIds) {
        return toAjax(omsTaskStepService.deleteOmsTaskStepByStepIds(stepIds));
    }
}
